package com.xyf.sys.util;

import com.xyf.sys.config.CustomException;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

/***
 * @title JDComputeChargeUtils
 * @description <TODO description class purpose>
 * @author Administrator
 * @version 1.0.0
 * @create 2024/8/29 17:31
 **/
public class JDComputeChargeUtils {

    public static double computeCharge(double weight, String receiverAddress) {
        double price = 0;
        List<String> parts = Arrays.asList(
                "陕西",  // 0
                "重庆", "安徽", "湖南", "江苏", "浙江", "上海", "江西", "贵州", "湖北", "山西", "福建", "河南", "四川", "青海", "宁夏", "甘肃", "辽宁", "北京", "天津", "河北", "山东", "广东", "海南", "广西", // 1-24
                "吉林", "黑龙江", "内蒙古", "云南", // 25-28
                "西藏", "新疆" // 29-30
        );
        int partsChoice = 0;
        for (int i = 0; i < parts.size(); i++) {
            String str = parts.get(i);
            if (receiverAddress.contains(str)) {
                partsChoice = i;
                break;
            }
        }
        weight = Math.ceil(weight);
        if (partsChoice == 0) {
            if (weight < 4) {
                price = 9 + (weight - 1);
            } else if (weight == 4) {
                price = 14;
            } else {
                price = 14 + (weight - 4) * 4;
            }
        } else if (partsChoice >= 1 && partsChoice <= 24) {
            if (weight <= 3) {
                price = 10 + (weight - 1);
            } else if (weight == 4) {
                price = 15;
            } else {
                price = 15 + (weight - 4) * 4;
            }
        } else if (partsChoice >= 25 && partsChoice <= 28) {
            if (weight <= 3) {
                price = 16.5 + (weight - 1);
            } else {
                price = 21.5 + (weight - 4) * 4;
            }
        } else if (partsChoice >= 29 && partsChoice <= 30) {
            throw new CustomException("邮寄省份暂不支持京东特惠价格");
        } else {
            throw new CustomException("未知省份无法获取京东特惠价格");
        }
        return price;
    }
}
